/**     
 * @Title: Application.java   
 * @Package bladeDemo   
 * @Description: TODO
 * @author weiwei 
 * @date 2018年4月16日 上午9:26:03   
 * @version V1.0     
 */
package bladeDemo;

import com.blade.Blade;
import com.blade.Environment;
import com.blade.event.EventType;
import com.blade.kit.StringKit;

/**
 * @ClassName: Application
 * @Description: TODO
 * @author weiwei
 * @date 2018年4月16日 上午9:26:03
 * 
 */
public class Application {

	/**
	 * @Title: main
	 * @Description: 文档： https://lets-blade.com/docs/index.html
	 *               git： https://gitee.com/biezhi/blade/tree/master
	 *               githut：https://github.com/lets-blade
	 * @param args
	 * @Reutrn void
	 */
	public static void main(String[] args) {
		Blade.me().before("/*", (request, response) -> {
			String uri = request.uri();
			if ("/index".equals(uri)) {
				String username = request.session().attribute(Const.LOGIN_SESSION_KEY);
				if (StringKit.isBlank(username)) {
					response.redirect("/login");
					return;
				}
			}
		}).event(EventType.SERVER_STARTED, (e) -> {
			Environment environment = e.blade().environment();
			Const.USERNAME = environment.get("app.username").get();
			Const.PASSWORD = environment.get("app.password").get();
		}).start(Application.class, args);
	}
}
